package com.huifaapp.mall.fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.ShoppingCartActivity;
import com.huifaapp.mall.adapter.EvaluateFragmentAdapter;
import com.huifaapp.mall.adapter.Itme_evaluaterecyclerview_imgeAdapter;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.bean.EvaluaueBean;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;
import java.util.List;

import static com.huifaapp.mall.uitils.Contig.typex;


/**
 * Created by 段昱 on 2017/12/14.
 */

public class EvaluateFragment extends Fragment {
    private static final String STATE_SAVE_IS_HIDDEN = "STATE_SAVE_IS_HIDDEN";

    private View view;
    private List<String> list;
    private XRecyclerView fragment_evaluate_recyclerView;
    private ArrayList<EvaluaueBean.DataBean.ListBean> dataBeanlsit;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.framgnet_evaluate, container, false);
        initView();
        initHttp();


        return view;
    }

    private void initHttp() {
        Bundle bundle = getArguments();//从activity传过来的Bundle
        if (bundle != null) {
            String shopid = bundle.getString("shopid");

            OkHttpUtils.post().addParams("id",shopid ).addParams("type","imge").url(ApiManager.BASE_NIUPAI_URL+typex+"/getSpuFeedbacks").build()
                    .execute(new StringCallback() {
                        @Override
                        public void onError(Request request, Exception e) {

                        }

                        @Override
                        public void onResponse(String response) {
                            Log.e("商品qqhou", response);
                            Gson gson=new Gson();
                            EvaluaueBean evaluaueBean = gson.fromJson(response, EvaluaueBean.class);
                            dataBeanlsit = new ArrayList<EvaluaueBean.DataBean.ListBean>();
                            dataBeanlsit.addAll(evaluaueBean.getData().getList());
                            EvaluateFragmentAdapter evaluateFragmentAdapter = new EvaluateFragmentAdapter(getActivity(), dataBeanlsit);
                            LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
                            fragment_evaluate_recyclerView.setLayoutManager(mLayoutManager);
                            fragment_evaluate_recyclerView.setAdapter(evaluateFragmentAdapter);
                            fragment_evaluate_recyclerView.setPullRefreshEnabled(false);
                        }
                    });
        }
    }
    private void initView() {
        fragment_evaluate_recyclerView = (XRecyclerView) view.findViewById(R.id.fragment_evaluate_RecyclerView);
    }

}
